package com.youkeda.app.service.impl;

import com.youkeda.app.dao.RedEnvelopeDao;
import com.youkeda.app.dataobject.RedEnvelopeDO;
import com.youkeda.app.model.RedEnvelope;
import com.youkeda.app.service.RedEnvelopeService;
import com.youkeda.app.util.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * @ClassName RedEnvelopeSeriveImpl
 * @Author 刘正星
 * @Date 2020/9/2 19:09
 **/
@Service
public class RedEnvelopeServiceImpl implements RedEnvelopeService {

    @Autowired
    private RedEnvelopeDao redEnvelopeDao;
    @Override
    public RedEnvelope save(RedEnvelope redEnvelope) {

        if (redEnvelope == null){
            return null;
        }

        RedEnvelopeDO redEnvelopeDO = new RedEnvelopeDO(redEnvelope);
        if (StringUtils.isEmpty(redEnvelopeDO.getId())){
            redEnvelopeDO.setId(UUIDUtils.getUUID());
        }
        redEnvelopeDao.insert(redEnvelopeDO);

        return redEnvelope;
    }
}
